/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package serverside;

import java.io.*;
import java.net.*;
import java.util.HashMap;
import java.io.*;
import java.net.*;
import com.cse.p2p.common.*;
import com.cse.p2p.database.*;
import com.cse.p2p.hash.*;
import com.cse.p2p.localfile.*;
import com.cse.p2p.parser.*;
import java.util.HashMap;
import javax.sql.CommonDataSource;
import server.dicfile.DicFileGenerating;
import server.network.ServerControlTask_Server;

/**
 *
 * @author TuyetNgan
 */
public class ControlServerSide extends Thread {
	
	private DataServerSide dataThread = null;
	
	private static Integer portControl = CommonSettings.SERVER_SERVERSOCKET;
	private static HashMap<String, String> peerOnline = new HashMap();

	@Override
	public void run() {
		// TODO code application logic here
		try {
			ServerSocket serverSocket = null;
			boolean listening = true;
			int count = 0;
			serverSocket = new ServerSocket( portControl );
			while ( listening ) {
				( new ServerControlTask_Server( serverSocket.accept(), count, peerOnline, dataThread ) ).start();
				count++;
			}
			serverSocket.close();
		}
		catch ( IOException e ) {
			System.out.println( "Cannot start server" );
		}
		
	}
	
	public void setDataThread(DataServerSide thread) {
		this.dataThread = thread;
	}
}
